package com.itheima.edu.info.manager.B_Controller;

import com.itheima.edu.info.manager.C_Service.LaoShiService;
import com.itheima.edu.info.manager.E_domain.LaoShi;
import java.util.ArrayList;
import java.util.Scanner;

public class LaoShiController {
    private Scanner sc = new Scanner(System.in);
    private ArrayList<LaoShi> list;
    private LaoShiService laoShiServices = new LaoShiService();
    private LaoShi laoShi = new LaoShi();

    public void jieshou() {
        lo:
        while (true) {
            System.out.println("--------欢迎来到教师管理系统--------");
            System.out.println("1 添加教师  2 修改教师  3 删除教师  4 查看教师  5 退出");
            int a = sc.nextInt();
            switch (a) {
                case 1: {
                    tianjia();
                    break;
                }
                case 2: {
                    xiuGai();
                    break;
                }
                case 3: {
                    shanChu();
                    break;
                }
                case 4: {
                    chaKan();
                    break;
                }
                case 5: {
                    break lo;
                }
            }
        }
    }

    private void tianjia() {
        while (true) {
            LaoShi ls = new LaoShi();
            System.out.println("请输入工号");
            String id = sc.next();
            if (laoShiServices.panDuanID(id)) {
                System.out.println("工号重复");
            } else {
                System.out.println("请输入姓名");
                String name = sc.next();
                System.out.println("请输入年龄");
                int age = sc.nextInt();
                ls.setID(id);
                ls.setName(name);
                ls.setAge(age);
                laoShiServices.tianjia(ls);
                System.out.println("添加成功");
                return;
            }
        }
    }

    private void xiuGai() {
        if (list == null || list.isEmpty()) {
            System.out.println("并无教师");
            return;
        }
        while (true) {

            System.out.println("请输入要修改的教师的工号");
            String s = sc.next();
            if (laoShiServices.panDuanID(s)) {
                System.out.println("请输入修改的姓名");
                String name = sc.next();
                System.out.println("请输入修改的年龄");
                int age = sc.nextInt();
                laoShi.setID(s);
                laoShi.setName(name);
                laoShi.setAge(age);
                laoShiServices.xiuGai(laoShi);
                System.out.println("修改成功");
                return;
            } else {
                System.out.println("工号不存在");
                return;
            }
        }
    }

    private void shanChu() {
        if (list == null || list.isEmpty()) {
            System.out.println("并无教师");
            return;
        }
        System.out.println("请输入要删除的教师的工号");
        String s = sc.next();
        if (laoShiServices.panDuanID(s)) {
            laoShiServices.shanChu(s);
        } else {
            System.out.println("并无此工号");
        }
    }

    private void chaKan() {
        list = laoShiServices.chaKan();
        if (list == null || list.isEmpty()) {
            System.out.println("并无教师");
            return;
        } else {
            for (int i = 0; i < list.size(); i++) {
                LaoShi ls = list.get(i);
                System.out.println("工号\t\t姓名\t\t年龄\t\t");
                System.out.println(ls.getID() + "\t\t" + ls.getName() + "\t\t" + ls.getAge());
            }
        }
    }
}

